@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')

@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <div id="cur-position">
                <span class="tit">公告设置：</span>
                <a href="{{route('Admin.Home.noticeSet')}}"></a>
            </div>
        </div>
        @include("admin.common.banner-header")


        <div class="gg-step">
            <form  id="advform">


                <div class="gg-list">
                    <label class="tit">标题：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入标题" name="title" id="title" value="@if($notice){{$notice->title}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">类型：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入描述" name="type" id="type" value="@if($notice){{$notice->type}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">描述：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入描述" name="desc" id="desc" value="@if($notice){{$notice->desc}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list" data-id="ggwz">
                    <label class="tit">内容：</label>
                    <div class="cont">
                        <textarea placeholder="请输入详情" name="description" id="aa"></textarea>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send" data-id="@if($notice){{$notice->id}}@endif">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            <!-- 实例化编辑器 -->
            var ue = UE.getEditor('aa',{
                autoHeightEnabled: true,
                initialFrameHeight:400,
                initialFrameWidth:600,
                toolbars: [
                    ['fullscreen', 'source','undo','redo','|','fontsize','horizontal','|','simpleupload','insertvideo','removeformat'],
                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
                ]
            });

            @if($notice)
            ue.ready(function() {
                ue.setContent('<?php echo $notice->content ?>');
            });
            @endif

            $('#btn_send').click(function () {
                var type        = $('#type').val();
                var title       = $('#title').val();
                var desc      = $('#desc').val();
                var id        = $(this).data("id");
                var content = "";

                ue.ready(function() {
                    content = ue.getContent();
                });

                $.ajax({
                    url: "{{route('Api.Admin.sys.setNotice')}}",
                    type: 'post',
                    dataType: 'json',
                    data: {

                        type:type,
                        title: title,
                        id:id,
                        content:content,
                        desc:desc,

                    },
                    success: function (obj) {
                        if (obj.level == 'success') {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose: function () {
                                        window.location.href="{{route("Admin.Home.noticeList")}}";
                                    }
                                }
                            });
                        } else {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }
                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

        });
    </script>
@endsection